<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="../../v2/common/jspcommon.jsp"%>
<title>添加新订单</title>
<script type="text/javascript">
<!--
	$(function() {
		//初始化
		initProvince('province', 'city', 'county', 'town');
		provinceChange("province","city","county","town","${order.provinceCode}","${order.cityCode}","${order.countyCode}","${order.townCode}");
		$.metadata.setType("attr", "validate");
		$("#product_form").validate({
			success : function(label) {
				label.text("").addClass("validate_success");
			},
			rules : {
				order_name : {
					required : true,
				},
				nickname : {
					required : true
				},
				product_name:{
					required : true
				},
				amount:{
					required : true
				},
				memberName:{
					required : true
				},
				phone:{
					required : true
				},
				address:{
					required : true
				}
			},
			messages : {
				order_name : {
					required : "不能为空",
				},
				nickname : {
					required : "不能为空"
				},
				product_name:{
					required : "不能为空"
				},
				amount:{
					required : "不能为空"
				},
				memberName:{
					required : "不能为空"
				},
				phone:{
					required : "不能为空"
				},
				address:{
					required : "不能为空"
				}

			},
			//提交由submitHandler拦截
			submitHandler : function() {
				$.post("/misc/product/saveOrder.htm",{
					title:$("#order_name").val(),
					nickname:$("#nickname").val(),
					quantity:$("#amount").val(),
					addressee:$("#memberName").val(),
					phone:$("#phone").val(),
					address:$("#address").val(),
					provinceCode:$("#province").val(),
					province:$("#province").find("option:selected").text(),
				    cityCode:$("#city").val(),
				    city:$("#city").find("option:selected").text(),
				    countyCode:$("#county").val(),
				    county:$("#county").find("option:selected").text(),
				    townCode:$("#town").val(),
				    town:$("#town").find("option:selected").text(),
					product:$("#product_name").val(),
					remark:$("#description").val()
				},function(data){
					alert(data);
				});	
				
			}

		});
	});
	
	
	function updateOrderByOrderId(){
		$.post("/misc/product/updateOrderByOrderId.htm",{
			identifier:$("#identifier").val(), 
			title:$("#order_name").val(),
			nickname:$("#nickname").val(),
			quantity:$("#amount").val(),
			addressee:$("#memberName").val(),
			phone:$("#phone").val(),
			address:$("#address").val(),
			provinceCode:$("#province").val(),
			province:$("#province").find("option:selected").text(),
		    cityCode:$("#city").val(),
		    city:$("#city").find("option:selected").text(),
		    countyCode:$("#county").val(),
		    county:$("#county").find("option:selected").text(),
		    townCode:$("#town").val(),
		    town:$("#town").find("option:selected").text(),
			product:$("#product_name").val(),
			remark:$("#description").val()
		},function(data){
			if(data=='success'){
				clearRushStyle();
				$('#product_content').load("/misc/product/readOrder.htm");
			}
		});	
	}
//-->
</script>




</head>
<body>

<form id="product_form">
	<table border="1" width="80%" style="margin-top: 20px;">
				<tr >
					<td>订单名称：</td>
					<td>
						<input type="text" style="width: 200px" id="order_name" name="order_name" value="${order.title}"/>
						<input type="hidden" style="width: 200px" id="identifier" name="identifier" value="${order.identifier}"/>
					</td>
				</tr>
				<tr>
					<td>用户昵称：</td>
					<td>
						<input type="text" style="width: 200px" id="nickname" name="nickname" value="${order.nickname}" />
						(*必须是果果街注册用户昵称)
					</td>
					
				</tr>
				<tr >
					<td>商品名称：</td>
					<td>
						<input type="text" style="width: 200px" id="product_name" name="product_name" value="${order.productName}"/>
						(*必须与产品标题一致)
					</td>
				</tr>
				<tr>
					<td>数量：</td>
					<td>
						<input type="text" style="width: 200px" id="amount" name="amount" value="${order.productQuantity}" />
					</td>
					
				</tr>
				<tr>
					<td>收件人联系方式：</td>
					<td>
						&nbsp;&nbsp;*姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：<input type="text"  id="memberName" name="memberName" value="${order.addressee}" />
						<br />&nbsp;&nbsp;*手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机：<input type="text" id="phone" name="phone" value="${order.phone}" />
					</td>
				
				</tr>
				<tr>
					<td>收货地址：</td>
					<td>
						&nbsp;&nbsp;*详细地址：
						<select id="province" name="province" ></select>
						<select id="city" name="city"></select>
						<select id="county" name="county"></select>
						<select id="town" name="town"></select>
						<input type="text"  id="address" value="${order.address}" name="address"/>
						<br />&nbsp;&nbsp;*邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;编：<input type="text" id="zipcode" name="zipcode" value="${order.zipcode}" />
					</td>
				
				</tr>
				<tr>
					<td>备注：</td>
					<td>
						<textarea style="height: 100px; width: 500px;"
						id="description" name="description" >${order.remark}</textarea>
					</td>
				
				</tr>
				<tr >
					<td style="text-align: center;" colspan="3">
					<c:choose>
						<c:when test="${not empty order.identifier}">
							<input type="button" value="更新订单" onclick="updateOrderByOrderId();" style="width: 150px"/>
							&nbsp;&nbsp;&nbsp;
						</c:when>
						<c:otherwise>
							<input type="submit" value="添加新订单" style="width: 150px" />
						</c:otherwise>
					</c:choose>
					
					
					<input type="button" style="width: 100px" value="取消" onclick="closed();"/>
					</td>
				</tr>
	</table>
	</form>
	
	
</body>
</html>